package com.zzl.finance.data.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzl.finance.data.constant.*;
import com.zzl.finance.data.dao.EnterpriseDao;
import com.zzl.finance.data.dto.KeyValue;
import com.zzl.finance.data.dto.*;
import com.zzl.finance.data.dto.feign.*;
import com.zzl.finance.data.entity.BankAccountEntity;
import com.zzl.finance.data.entity.EnterpriseEntity;
import com.zzl.finance.data.entity.EnterprisePersonEntity;
import com.zzl.finance.data.entity.EnterpriseRelationEntity;
import com.zzl.finance.data.feign.BondsTicketFeign;
import com.zzl.finance.data.feign.FileCenterFeign;
import com.zzl.finance.data.feign.UserCenterFeign;
import com.zzl.finance.data.service.BankAccountService;
import com.zzl.finance.data.service.EnterprisePersonService;
import com.zzl.finance.data.service.EnterpriseRelationService;
import com.zzl.finance.data.service.EnterpriseService;
import com.zzl.general.common.constant.Constant;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.requestparameter.Ids;
import com.zzl.general.common.requestparameter.KeyAndValue;
import com.zzl.general.common.serurity.entity.User;
import com.zzl.general.common.third.sms.config.RedisTemplateClient;
import com.zzl.general.common.utils.*;
import com.zzl.sharding.user.dto.OrganizationAndUserAddDto;
import com.zzl.sharding.user.dto.UserAddDto;
import com.zzl.sharding.user.entity.UserEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.SocketUtils;

import java.util.*;
import java.util.stream.Collectors;

import static com.zzl.general.common.utils.ResultCode.SUCCESS;

/**
 * @author gull
 * @date 2021-11-09 20:04:58
 */
@Service("enterpriseService")
public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseDao, EnterpriseEntity> implements EnterpriseService {


    @Autowired
    private UserCenterFeign userCenterFeign;
    @Autowired
    private EnterpriseRelationService enterpriseRelationService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Value("#{'${config.approveOpen}'.equals('on')}")
    private boolean configApproveOpen;

    @Autowired
    private FileCenterFeign fileCenterFeign;
    @Autowired
    private BankAccountService bankAccountService;

    @Autowired
    private EnterprisePersonService enterprisePersonService;
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private BondsTicketFeign bondsTicketFeign;

    /**
     * 企业认证
     *
     * @param enterpriseCertificationUpdateDto 企业信息
     * @param user                             用户
     * @throws SysException 异常
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveEnterprise(VoucherEnterpriseCertificationUpdateDto enterpriseCertificationUpdateDto, User user) throws SysException {
        List<VoucherUserUpdateDto> voucherUserUpdateDtos = enterpriseCertificationUpdateDto.getVoucherUserUpdateDtos();
        if (voucherUserUpdateDtos.size() < 2) {
            throw new SysException("请确认添加财务负责人和法人!");
        }
        List<Integer> personnelTypes = voucherUserUpdateDtos.stream().map(VoucherUserUpdateDto::getPersonnelType).distinct().collect(Collectors.toList());
        if (!personnelTypes.containsAll(PersonTypeEnum.getEnterPrisePerson())) {
            throw new SysException("请确认添加财务负责人和法人!");
        }

        EnterpriseEntity byId = this.getById(user.getEnterpriseId());
        //非管理员认证状态，不允许调用资料完善接口
        if (!ProgressStatusEnum.PROGRESS_STATUS_CERTIFIED.getKey().equals(byId.getProgressStatus()) &&
                !ProgressStatusEnum.PROGRESS_STATUS_ADMIN_AUTH.getKey().equals(byId.getProgressStatus())) {
            throw new SysException("当前企业不处于资料完善环节!");
        }
        //处理企业信息存储
        VoucherEnterpriseUpdateDto voucherEnterpriseUpdate = enterpriseCertificationUpdateDto.getVoucherEnterpriseUpdate();
        EnterpriseEntity enterpriseEntity = new EnterpriseEntity();
        BeanUtils.copyProperties(voucherEnterpriseUpdate, enterpriseEntity);
        enterpriseEntity.setId(user.getEnterpriseId());
        enterpriseEntity.setApproveStatus(Integer.parseInt(ApproveStatusStringConstant.APPROVE_STATUS_ING.getKey()));
        enterpriseEntity.setProgressStatus(ProgressStatusEnum.PROGRESS_STATUS_DATA_IMPROVEMENT.getKey());
        this.updateById(enterpriseEntity);
        //存储人员信息
        this.saveEnterprisePeople(enterpriseCertificationUpdateDto, user, enterpriseEntity);
        //存储银行账号信息
        this.saveBankAccount(enterpriseEntity, enterpriseCertificationUpdateDto.getVoucherBankAccountUpdateDto(), user);
    }

    /**
     * 企业认证-资料修改
     *
     * @param enterpriseCertificationUpdateDto 企业信息
     * @param user                             用户
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateEnterpriseData(VoucherEnterpriseCertificationUpdateDto enterpriseCertificationUpdateDto, User user) throws SysException {

        VoucherEnterpriseUpdateDto voucherEnterpriseUpdate = enterpriseCertificationUpdateDto.getVoucherEnterpriseUpdate();
        voucherEnterpriseUpdate.setEnterpriseFreezingStatus(EnterpriseStatusEnum.ENTERPRISE_STATUS_FREEZING.getCode());
        //1、修改企业信息
        this.saveEnterprise(enterpriseCertificationUpdateDto, user);
        //2、冻结所有票据  todo
    }

    /**
     * 保存企业账户信息
     *
     * @param enterpriseEntity 企业信息
     * @param accountUpdateDto 账户信息
     * @param user             用户信息
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveBankAccount(EnterpriseEntity enterpriseEntity, VoucherBankAccountUpdateDto accountUpdateDto, User user) {
        BankAccountEntity bankAccountEntity = new BankAccountEntity();
        BeanUtils.copyProperties(accountUpdateDto, bankAccountEntity);
        bankAccountEntity.setStopState(true);
        bankAccountEntity.setIsSetTop(0);
        bankAccountEntity.setCreatorId(user.getId());
        bankAccountEntity.setEnterpriseId(enterpriseEntity.getId());
        bankAccountEntity.setEnterpriseCategory(enterpriseEntity.getCategory());
        bankAccountEntity.setEnterpriseName(enterpriseEntity.getEnterpriseName());
        bankAccountEntity.setRegisterAccount(1);
        if (StringUtils.isBlank(bankAccountEntity.getId())) {
            bankAccountEntity.setId(UuidUtils.UUID());
        }
        bankAccountService.saveOrUpdate(bankAccountEntity);
    }

    /**
     * 保存企业人员信息
     *
     * @param enterpriseCertificationUpdateDto 企业人员信息
     * @param user                             用户
     * @param enterpriseEntity                 企业信息
     * @throws SysException 异常
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveEnterprisePeople(VoucherEnterpriseCertificationUpdateDto enterpriseCertificationUpdateDto, User user, EnterpriseEntity enterpriseEntity) throws SysException {
        QueryWrapper<EnterprisePersonEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EnterprisePersonEntity::getEnterpriseId, user.getEnterpriseId());
        List<EnterprisePersonEntity> list = enterprisePersonService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            List<String> collect = list.stream().map(EnterprisePersonEntity::getId).collect(Collectors.toList());
            enterprisePersonService.removeByIds(collect);
        }
        List<EnterprisePersonEntity> dtos = new ArrayList<>();
        //处理人员信息存储
        List<VoucherUserUpdateDto> voucherUserUpdateDtos = enterpriseCertificationUpdateDto.getVoucherUserUpdateDtos();
        for (VoucherUserUpdateDto voucherUserUpdateDto : voucherUserUpdateDtos) {
            EnterprisePersonEntity enterprisePersonEntity = new EnterprisePersonEntity();
            BeanUtils.copyProperties(voucherUserUpdateDto, enterprisePersonEntity);
            enterprisePersonEntity.setEnterpriseId(user.getEnterpriseId());
            enterprisePersonEntity.setId(UuidUtils.UUID());
            enterprisePersonEntity.setCreatorId(user.getId());
            enterprisePersonEntity.setUpdaterId(user.getId());
            dtos.add(enterprisePersonEntity);
        }
        if (!enterprisePersonService.saveOrUpdateBatch(dtos)) {
            throw new SysException("新增人员失败！");
        }
    }


    /**
     * 处理企业申请审批
     *
     * @param approveDto 审批信息
     * @param user       用户
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void approveEnterprise(ApproveDto approveDto, User user) throws SysException {
        EnterpriseEntity enterpriseEntity = this.getById(approveDto.getId());
        if (!ApproveStatusConstant.APPROVE_STATUS_ING.getKey().equals(enterpriseEntity.getApproveStatus())) {
            throw new SysException("企业未处于审核中！");
        }
        //审核通过，则修改状态，并且发送打款认证
        if (ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey().equals(approveDto.getApproveStatus())) {
            enterpriseEntity.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
            enterpriseEntity.setProgressStatus(ProgressStatusEnum.PROGRESS_STATUS_PLATFORM_APPROVE.getKey());
            //若为修改信息后的审核通过，则需要解冻所有票据 todo
            if (EnterpriseStatusEnum.ENTERPRISE_STATUS_FREEZING.getCode().equals(enterpriseEntity.getEnterpriseFreezingStatus())) {
                enterpriseEntity.setEnterpriseFreezingStatus(EnterpriseStatusEnum.ENTERPRISE_STATUS_UNFREEZING.getCode());
            }
            //发送打款认证消息并发送手机提示  todo  PaymentCertificationRecordDto

        } else {
            //审核不通过
            enterpriseEntity.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_REFUSE.getKey());
        }
        enterpriseEntity.setUpdaterId(user.getId());
        this.updateById(enterpriseEntity);
    }

    /**
     * 平台注册企业
     *
     * @param enterpriseCertificationUpdateDto 企业信息
     * @param user                             用户
     * @throws SysException 异常
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void platformVoucherRegister(VoucherEnterpriseCertificationUpdateDto enterpriseCertificationUpdateDto, User user) throws SysException {
        List<VoucherUserUpdateDto> voucherUserUpdateDtos = enterpriseCertificationUpdateDto.getVoucherUserUpdateDtos();
        if (voucherUserUpdateDtos.size() < 2) {
            throw new SysException("请确认添加财务负责人和法人!");
        }
        List<Integer> personnelTypes = voucherUserUpdateDtos.stream().map(VoucherUserUpdateDto::getPersonnelType).distinct().collect(Collectors.toList());
        if (!personnelTypes.containsAll(Arrays.asList(2, 3))) {
            throw new SysException("请确认添加财务负责人和法人!");
        }

        //处理企业信息存储
        EnterpriseEntity enterpriseEntity = new EnterpriseEntity();
        String enterpriseId = UuidUtils.UUID();
        enterpriseEntity.setId(enterpriseId);
        BeanUtils.copyProperties(enterpriseCertificationUpdateDto.getVoucherEnterpriseUpdate(), enterpriseEntity);
        enterpriseEntity.setCategory(UserCategoryConstant.USER_CATEGORY_SUPPLIER.getKey());
        enterpriseEntity.setApproveStatus(Integer.parseInt(ApproveStatusStringConstant.APPROVE_STATUS_ING.getKey()));
        enterpriseEntity.setBusinessType(BusinessTypeEnum.ACCOUNT_ENABLE.getCode());
        enterpriseEntity.setLatestStatus(1);
        enterpriseEntity.setProgressStatus(ProgressStatusEnum.PROGRESS_STATUS_PLATFORM_APPROVE.getKey());
        if (!this.save(enterpriseEntity)) {
            throw new SysException("新增企业失败！");
        }
        List<EnterpriseEntity> enterpriseEntity1 = this.getOneBySocialCreditCode(enterpriseEntity.getSocialCreditCode());
        if (enterpriseEntity1.size() > 1) {
            throw new SysException("企业社会统一代码重复！");
        }
        user.setEnterpriseId(enterpriseEntity.getId());
        //存储人员信息
        this.saveEnterprisePeople(enterpriseCertificationUpdateDto, user, enterpriseEntity);
        //存储银行账号信息
        this.saveBankAccount(enterpriseEntity1.get(0), enterpriseCertificationUpdateDto.getVoucherBankAccountUpdateDto(), user);
        //todo 保存管理员信息
        UserAdminEntity userAdminEntity = enterpriseCertificationUpdateDto.getUserAdminEntity();
        UserManegeAddDto userAddDto = new UserManegeAddDto();
        userAddDto.setUserAccount(userAdminEntity.getUserAccount());
        userAddDto.setUserNameCertification(userAdminEntity.getUserName());
        userAddDto.setUserCertification(userAdminEntity.getUserCertification());
        userAddDto.setUserPhone(userAdminEntity.getUserPhone());
        userAddDto.setEnterpriseId(enterpriseId);
        userAddDto.setEnterpriseName(enterpriseEntity.getEnterpriseName());
        userAddDto.setUserCategory(UserCategoryConstant.USER_CATEGORY_SUPPLIER.getKey());
        userAddDto.setUserManage(1);
        userAddDto.setCertificatesType("0");
        Result result = userCenterFeign.saveManegeUser(userAddDto);
        userAddDto.setCertificatesType("0");
    }

    /**
     * 查找核心企业
     *
     * @return 核心企业id 拼接的字符串
     */
    @Override
    public String findCoreEnterPrise() {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EnterpriseEntity::getCategory, 0)
                .eq(EnterpriseEntity::getStopStatus, 1)
                .eq(EnterpriseEntity::getApproveStatus, ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        List<String> ids = list.stream().map(EnterpriseEntity::getId).distinct().collect(Collectors.toList());
        return StringUtils.join(ids, ",");
    }

    @Override
    public List<String> findCoreEnterPriseIds() {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(EnterpriseEntity::getCategory, Arrays.asList(0, 2))
                .eq(EnterpriseEntity::getStopStatus, 1)
                .eq(EnterpriseEntity::getApproveStatus, ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.stream().map(EnterpriseEntity::getId).distinct().collect(Collectors.toList());
    }

    /**
     * 查询所有核心企业
     *
     * @return 所有核心企业
     */
    @Override
    public List<EnterpriseEntity> getCoreEnterpriseList() {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(EnterpriseEntity::getCategory, Arrays.asList(0, 2))
                .eq(EnterpriseEntity::getStopStatus, 1)
                .eq(EnterpriseEntity::getApproveStatus, ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        return this.list(queryWrapper);
    }

    /**
     * 查找集团
     *
     * @return 集团实体
     */
    @Override
    public EnterpriseEntity findCoreGroup() {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EnterpriseEntity::getCategory, UserCategoryConstant.USER_CATEGORY_GROUP.getKey())
                .eq(EnterpriseEntity::getStopStatus, 1)
                .eq(EnterpriseEntity::getApproveStatus, ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        return this.getOne(queryWrapper);

    }

    @Override
    public Map<String, String> findCoreEnterPriseListId() {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(EnterpriseEntity::getCategory, Arrays.asList(0, 2))
                .eq(EnterpriseEntity::getStopStatus, 1)
                .eq(EnterpriseEntity::getApproveStatus, ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.stream().collect(Collectors.toMap(EnterpriseEntity::getId, EnterpriseEntity::getEnterpriseName, (key1, key2) -> key2));
    }

    /**
     * 分页查询
     *
     * @param params 查询参数 enterpriseName企业名称
     * @return 分页数据
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        /*TODO*/
        System.out.println(params.get("enterpriseName"));
        System.out.println("=-=-=-=-=-=-=-=-=-=");
        IPage<EnterpriseEntity> page = new Query<EnterpriseEntity>().getPage(params);
        LambdaQueryWrapper<EnterpriseEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EnterpriseEntity::getCategory,UserCategoryConstant.USER_CATEGORY_SUPPLIER.getKey())
                .eq(EnterpriseEntity::getStopStatus,EnterpriseStopStatusEnum.ENTERPRISE_STATUS_USING.getCode())
                .like(EnterpriseEntity::getEnterpriseName,params.get("enterpriseName"));
        IPage<EnterpriseEntity> enterpriseEntityIPage = page(page,lambdaQueryWrapper);
        List<EnterpriseEntity> list = enterpriseEntityIPage.getRecords();
        System.out.println(list);
        System.out.println("==========---=--===-==-");
        return new PageUtils(enterpriseEntityIPage);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveVoucherSupplier(VoucherEnterpriseAddDto supplier) throws SysException {
        //4 供应商添加或修改
        EnterpriseEntity enterprise = new EnterpriseEntity();
        //4.1 查询供应商是否存在，开立业务，若签收方供应商不存在，则会新增供应商基本信息
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EnterpriseEntity::getSocialCreditCode, supplier.getSocialCreditCode());
        queryWrapper.eq(EnterpriseEntity::getEnterpriseName, supplier.getEnterpriseName());
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            enterprise.setId(list.get(0).getId());
        }
        BeanUtils.copyProperties(supplier, enterprise);
        enterprise.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_ING.getKey());
        enterprise.setCategory(1);
        if (!this.saveOrUpdate(enterprise)) {
            throw new SysException("A00001", "保存失败！");
        }

        //2 管理员用户添加
        UserAddDto userAddDto = new UserAddDto();
        userAddDto.setUserPhone(supplier.getAdminPhone());
        userAddDto.setUserName(supplier.getUserName());
        userAddDto.setUserPassword(supplier.getUserPassword());
        userAddDto.setFirstLogin(StringConstant.FIRST_LOGIN);
        userAddDto.setUserManage(Constant.SUPER_ADMIN);
        userAddDto.setUserCategory(supplier.getCategory());
        userAddDto.setEnterpriseId(enterprise.getId());
        userAddDto.setEnterpriseName(enterprise.getEnterpriseName());
        Result result = userCenterFeign.saveUser(userAddDto);
        if (ResultCode.SUCCESS.getCode() != result.getCode()) {
            throw new SysException(result.getMsg());
        }
        UserEntity userEntity = JSON.parseObject(JSON.toJSONString(result.getResult().get("data")), UserEntity.class);
        if (null == userEntity || userEntity.getId() == null) {
            throw new SysException("用户保存失败！");
        }
    }


    @Override
    public PageUtils platformQueryPage(Map<String, Object> params) {
        params.put("approveStatus", Collections.singletonList(ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey()));
        //排序字段：create_time
        String pageField = (String) params.get(Constant.PAGE);
        //排序方式 order:  desc asc
        String order = (String) params.get(Constant.ORDER);
        IPage<EnterpriseEntity> page = new Query<EnterpriseEntity>()
                .getPage(params, StringUtils.isBlank(pageField) ? StringConstant.CREATE_TIME_FILED : pageField, Constant.ASC.equals(order));
        IPage<EnterprisePage> transferPage = this.baseMapper.queryPage(page, params);
        List<EnterprisePage> list = transferPage.getRecords();
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(e -> {
                if (e.getEnterpriseFreezingStatus() == 0) {
                    e.setOperateButton(Arrays.asList(new KeyValue("详情"), new KeyValue("编辑")
                            , new KeyValue("冻结"), new KeyValue("发票信息")));
                } else {
                    e.setOperateButton(Arrays.asList(new KeyValue("详情"), new KeyValue("编辑")
                            , new KeyValue("启用"), new KeyValue("发票信息")));
                }
                e.setCategoryName(UserCategoryConstant.getStatus(e.getCategory()));
                e.setDataChannel("0".equals(e.getDataChannel()) ? "自建" : "注册");
                e.setEnterpriseFreezingStatusStr(0 == e.getEnterpriseFreezingStatus() ? "未启用" : "启用");
            });
        }
        return new PageUtils(transferPage);
    }

    @Override
    public List<EnterpriseEntity> getOneBySocialCreditCode(String socialCreditCode) {
        QueryWrapper<EnterpriseEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("social_credit_code", socialCreditCode);
        return baseMapper.selectList(queryWrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateEnterpriseById(VoucherEnterpriseCertificationUpdateDto enterpriseUpdateDto, User user) throws SysException {
        EnterpriseEntity enterpriseEntity = new EnterpriseEntity();
        BeanUtils.copyProperties(enterpriseUpdateDto.getVoucherEnterpriseUpdate(), enterpriseEntity);
        // tickeprotocolEntity.setUpdatedUserId(user.getId());
        if (!this.updateById(enterpriseEntity)) {
            throw new SysException("A00002", "修改失败！");
        }
        VoucherBankAccountUpdateDto voucherBankAccountUpdateDto = enterpriseUpdateDto.getVoucherBankAccountUpdateDto();
        UpdateWrapper<BankAccountEntity> bankAccountEntityUpdateWrapper = new UpdateWrapper<>();
        BankAccountEntity bankAccountEntity = bankAccountService.getByEnterpriseId(enterpriseEntity.getId());
        if (bankAccountEntity != null) {
            bankAccountEntityUpdateWrapper.set("corporate_account", voucherBankAccountUpdateDto.getCorporateAccount());
            bankAccountEntityUpdateWrapper.set("full_name_opening_bank", voucherBankAccountUpdateDto.getFullNameOpeningBank());
            bankAccountEntityUpdateWrapper.set("account_opening_outlet", voucherBankAccountUpdateDto.getAccountOpeningOutlet());
            bankAccountEntityUpdateWrapper.set("bank_number", voucherBankAccountUpdateDto.getBankNumber());
            bankAccountEntityUpdateWrapper.set("account_name", voucherBankAccountUpdateDto.getAccountName());
            bankAccountEntityUpdateWrapper.eq("enterprise_id", enterpriseEntity.getId());
            bankAccountEntityUpdateWrapper.eq("account_type", 4);
            bankAccountService.update(bankAccountEntityUpdateWrapper);
        } else {
            BankAccountEntity bankAccountEntity1 = new BankAccountEntity();
            bankAccountEntity1.setCorporateAccount(voucherBankAccountUpdateDto.getCorporateAccount());
            bankAccountEntity1.setAccountName(voucherBankAccountUpdateDto.getAccountName());
            bankAccountEntity1.setFullNameOpeningBank(voucherBankAccountUpdateDto.getFullNameOpeningBank());
            bankAccountEntity1.setAccountOpeningOutlet(voucherBankAccountUpdateDto.getAccountOpeningOutlet());
            bankAccountEntity1.setBankNumber(voucherBankAccountUpdateDto.getBankNumber());
            bankAccountEntity1.setAccountType(4);
            bankAccountEntity1.setCreatorId(user.getId());
            bankAccountEntity1.setEnterpriseId(enterpriseEntity.getId());
            bankAccountEntity1.setEnterpriseCategory(enterpriseEntity.getCategory());
            bankAccountEntity1.setEnterpriseName(enterpriseEntity.getEnterpriseName());
            bankAccountService.save(bankAccountEntity1);
        }

    }

    /**
     * 校验打款认证
     *
     * @param paymentCertificationDto 打款认证信息
     * @param user                    用户
     */
    @Override
    public void checkPaymentCertification(PaymentCertificationDto paymentCertificationDto, User user) throws SysException {
        //todo 校验打款认证金额，通过后创建组织架构
        // 创建组织机构
        OrganizationAndUserAddDto organizationAndUserAddDto = new OrganizationAndUserAddDto();
        // 创建组织机构
        organizationAndUserAddDto.setOrgName(user.getEnterpriseName());
        //关联供应商角色
        organizationAndUserAddDto.setSupplierRoleId(StringConstant.ORG_SUPPLIER);
        organizationAndUserAddDto.setEnterpriseId(user.getEnterpriseId());
        Result result = userCenterFeign.saveOrganizationAndRole(organizationAndUserAddDto);
        if (ResultCode.SUCCESS.getCode() != result.getCode()) {
            throw new SysException(result.getMsg());
        }
        //打款认证通过，需要将企业进度状态更新为完成认证
        EnterpriseEntity enterpriseEntity = new EnterpriseEntity();
        enterpriseEntity.setId(user.getEnterpriseId());
        enterpriseEntity.setProgressStatus(ProgressStatusEnum.PROGRESS_STATUS_CERTIFIED.getKey());
        if (!this.updateById(enterpriseEntity)) {
            throw new SysException("更新失败");
        }

        EnterpriseEntity byId = enterpriseService.getById(user.getEnterpriseId());
        //如果是邀请注册用户，则需要添加企业白名单
        if (!StringUtils.isBlank(byId.getInvitationEnterpriseId())) {
            BwRelationAddDto bwRelationAddDto = new BwRelationAddDto();
            bwRelationAddDto.setEnterpriseGrade(EnterPriseGradeEnum.ONE.getCode());
            bwRelationAddDto.setEnterpriseId(user.getEnterpriseId());
            bwRelationAddDto.setIsBlackList(BlackListTypeEnum.WHITE_LIST_TYPE.getKey());
            bwRelationAddDto.setRemark("邀请链接注册");
            enterpriseRelationService.saveEnterpriseRelation(bwRelationAddDto, user);
        }


    }

    /**
     * 企业信息查询
     *
     * @param enterpriseId 企业id
     * @return
     * @throws SysException 异常
     */
    @Override
    public VoucherEnterpriseCertificationUpdateDto getInfo(String enterpriseId) throws SysException {
        VoucherEnterpriseCertificationUpdateDto result = new VoucherEnterpriseCertificationUpdateDto();
        EnterpriseEntity enterpriseEntity = this.getById(enterpriseId);
        VoucherEnterpriseUpdateDto voucherEnterpriseUpdate = new VoucherEnterpriseUpdateDto();
        BeanUtils.copyProperties(enterpriseEntity, voucherEnterpriseUpdate);
        result.setVoucherEnterpriseUpdate(voucherEnterpriseUpdate);
        //银行账户
        BankAccountEntity bankAccountEntity = bankAccountService.getByEnterpriseId(enterpriseId);
        if (bankAccountEntity != null) {
            VoucherBankAccountUpdateDto voucherBankAccountUpdateDto = new VoucherBankAccountUpdateDto();
            BeanUtils.copyProperties(bankAccountEntity, voucherBankAccountUpdateDto);
            result.setVoucherBankAccountUpdateDto(voucherBankAccountUpdateDto);
        }
        //企业人员
        QueryWrapper<EnterprisePersonEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EnterprisePersonEntity::getEnterpriseId, enterpriseId);
        List<EnterprisePersonEntity> list = enterprisePersonService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            List<VoucherUserUpdateDto> voucherUserUpdateDtos = QmBeanUtils.copyListProperties(list, VoucherUserUpdateDto::new);
            result.setVoucherUserUpdateDtos(voucherUserUpdateDtos);
        }
        return result;
    }

    @Override
    public Map<String, String> getSocialCreditCode(List<String> ids) {

        ids.removeIf(Objects::isNull);
        List<KeyAndValue> socialCreditCode = baseMapper.getSocialCreditCode(ids);
        return socialCreditCode.stream().collect(Collectors.toMap(KeyAndValue::getKey, KeyAndValue::getValue, (key1, key2) -> key2));
    }

    @Override
    public EnterpriseEntity getLoginUserEnterprise(User user) throws SysException {
        return this.getById(user.getEnterpriseId());
    }

    @Override
    public PageUtils listPage(Map<String, Object> params) throws SysException {
        //排序字段：create_time
        String pageField = (String) params.get(Constant.PAGE);
        //排序方式 order:  desc asc
        String order = (String) params.get(Constant.ORDER);
        IPage<EnterpriseEntity> page = new Query<EnterpriseEntity>()
                .getPage(params, StringUtils.isBlank(pageField) ? StringConstant.CREATE_TIME_FILED : pageField, Constant.ASC.equals(order));
        IPage<PlatEnterprisePage> transferPage = this.baseMapper.listPage(page, params);
        List<PlatEnterprisePage> list = transferPage.getRecords();
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(e -> {
                e.setCategoryName(UserCategoryConstant.getStatus(e.getCategory()));
                e.setBusinessTypeStr(BusinessTypeEnum.getValue(e.getBusinessType()));
                e.setOperateButton(Arrays.asList(new KeyValue("审核")));
            });
        }
        return new PageUtils(transferPage);
    }

    @Override
    public void covertPage(VoucherEnterpriseCertificationUpdateDto supplier) {
        List<UserEntity> adminInfo = userCenterFeign.getAdminInfo(Collections.emptyList());
        if (!CollectionUtils.isEmpty(adminInfo)) {
            UserEntity userEntity = adminInfo.get(0);
            if (userEntity != null) {
                UserAdminEntity userAdminEntity = new UserAdminEntity();
                BeanUtils.copyProperties(userEntity, userAdminEntity);
                supplier.setUserAdminEntity(userAdminEntity);
            }
            Map<Integer, UserEntity> integerUserEntityMap = userCenterFeign.mapByIds(new Ids(Collections.singletonList(supplier.getVoucherEnterpriseUpdate().getCreatorId())));
            supplier.getVoucherEnterpriseUpdate().setCreatorName(integerUserEntityMap.get(supplier.getVoucherEnterpriseUpdate().getCreatorId()).getUserName());
        }
    }

    @Override
    public void platApproveEnterprise(ApproveDto approveDto, User user) throws SysException {
        EnterpriseEntity enterpriseEntity = this.getById(approveDto.getId());
        if (!ApproveStatusConstant.APPROVE_STATUS_ING.getKey().equals(enterpriseEntity.getApproveStatus())) {
            throw new SysException("企业未处于审核中！");
        }
        //审核通过，则修改状态，并且发送打款认证
        if (ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey().equals(Integer.parseInt(approveDto.getApproveStatus()))) {
            enterpriseEntity.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
            enterpriseEntity.setProgressStatus(ProgressStatusEnum.PROGRESS_STATUS_CERTIFIED.getKey());
        } else {
            //审核不通过
            enterpriseEntity.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_REFUSE.getKey());
        }
        enterpriseEntity.setUpdaterId(user.getId());
        this.updateById(enterpriseEntity);
        this.saveApproveLog(approveDto);
    }

    @Override
    public void setApproveLog(VoucherEnterpriseCertificationUpdateDto supplier) {
        List<ApproveLogEntity> logEntities = bondsTicketFeign.list(supplier.getVoucherEnterpriseUpdate().getId());
        List<Integer> userIds = logEntities.stream().map(ApproveLogEntity::getCreatorId).collect(Collectors.toList());
        Map<Integer, UserEntity> integerUserEntityMap = userCenterFeign.mapByIds(new Ids(userIds));
        logEntities.forEach(e -> e.setCreatorName(integerUserEntityMap.get(e.getCreatorId()).getUserName()));
        if (!CollectionUtils.isEmpty(logEntities)) {
            supplier.setLogEntities(logEntities);
        }
    }

    @Override
    public void freezingStatus(Map<String, Object> params) throws SysException {
        if (lambdaUpdate().eq(EnterpriseEntity::getId, params.get("id"))
                .set(EnterpriseEntity::getEnterpriseFreezingStatus, params.get("enterpriseFreezingStatus"))
                .update()) {
            throw new SysException("操作失败！");
        }
    }

    private void saveApproveLog(ApproveDto approveDto) {
        ApproveLogAddDto approveLog = new ApproveLogAddDto();
        approveLog.setBusinessId(approveDto.getId());
        approveLog.setApproveType(1);
        approveLog.setRemark(approveDto.getRemark());
        approveLog.setApproveResult(approveDto.getApproveStatus());
        approveLog.setEnterpriseId(approveDto.getId());
        bondsTicketFeign.approveLogSave(approveLog);
    }

    /**
     * 通过企业类型查询企业列表
     *
     * @param category 企业类型
     * @return 企业列表
     */
    @Override
    public List<EnterpriseEntity> getEnterpriseListByCategory(String category) {
        QueryWrapper<EnterpriseEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EnterpriseEntity::getCategory, category);
        return this.list(queryWrapper);
    }

    @Override
    public List<EnterpriseEntity> getGroup(User user) throws SysException {
        return lambdaQuery().eq(EnterpriseEntity::getCategory, UserCategoryConstant.USER_CATEGORY_GROUP.getKey())
                .eq(EnterpriseEntity::getProgressStatus, ProgressStatusEnum.PROGRESS_STATUS_CERTIFIED.getKey())
                .eq(EnterpriseEntity::getLatestStatus, 1).list();
    }

    /**
     * 新增
     *
     * @param supplierAddDto 新增实体
     * @throws SysException 业务异常
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveSupplier(EnterpriseAddDto supplierAddDto) throws SysException {
        //1、短信验证码校验
        //1.1 经办人验证码

        String handlerCode = (String) RedisTemplateClient.get(redisTemplate, SmsTypeConstant.USER_HANDLER_REGISTER + supplierAddDto.getSupplierPhone());
        if (configApproveOpen && !supplierAddDto.getSupplierPhoneCode().equals(handlerCode)) {
            throw new SysException("经办人验证码不正确");
        }
        // 1.2 法人验证码
        String legalCode = (String) RedisTemplateClient.get(redisTemplate, SmsTypeConstant.USER_LEGAL_REGISTER + supplierAddDto.getLegalPhone());
        if (configApproveOpen && !supplierAddDto.getLegalPhoneCode().equals(legalCode)) {
            throw new SysException("法人验证码不正确");
        }
        //1.3 校验企业信息是否存在
        this.checkEnterprise(supplierAddDto.getSocialCreditCode(), StringConstant.TYPE_TWO);

        //4 供应商添加或修改
        EnterpriseEntity enterprise = new EnterpriseEntity();
        //4.1 查询供应商是否存在，开立业务，若签收方供应商不存在，则会新增供应商基本信息
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EnterpriseEntity::getSocialCreditCode, supplierAddDto.getSocialCreditCode());
        queryWrapper.eq(EnterpriseEntity::getEnterpriseName, supplierAddDto.getEnterpriseName());
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            enterprise.setId(list.get(0).getId());
        }
        BeanUtils.copyProperties(supplierAddDto, enterprise);
        enterprise.setApproveStatus(ApproveStatusConstant.APPROVE_STATUS_ING.getKey());
        enterprise.setCategory(1);
        if (!this.saveOrUpdate(enterprise)) {
            throw new SysException("A00001", "保存失败！");
        }
        //2 用户添加
        UserAddDto userAddDto = new UserAddDto();
        userAddDto.setUserEmail(supplierAddDto.getSupplierEmail());
        userAddDto.setUserPhone(supplierAddDto.getSupplierPhone());
        userAddDto.setUserName(supplierAddDto.getUserName());
        userAddDto.setUserPassword(supplierAddDto.getSupplierPassword());
        userAddDto.setFirstLogin(StringConstant.FIRST_LOGIN);
        userAddDto.setUserManage(Constant.SUPER_ADMIN);
        userAddDto.setUserCategory(UserCategoryConstant.USER_CATEGORY_SUPPLIER.getKey());
        userAddDto.setEnterpriseId(enterprise.getId());
        Result result = userCenterFeign.saveUser(userAddDto);
        if (ResultCode.SUCCESS.getCode() != result.getCode()) {
            throw new SysException(result.getMsg());
        }
        UserEntity userEntity = JSON.parseObject(JSON.toJSONString(result.getResult().get("data")), UserEntity.class);
        if (null == userEntity || userEntity.getId() == null) {
            throw new SysException("用户保存失败！");
        }

        //3 法人添加 todo gull
//        LegalEntity legalEntity = new LegalEntity();
//        BeanUtils.copyProperties(supplierAddDto, legalEntity);
//        legalEntity.setEnterpriseId(enterprise.getId());
//        if (!legalService.save(legalEntity)) {
//            throw new SysException("保存法人失败！");
//        }
        //5 上级供应商关系添加
        if (null != supplierAddDto.getSupplierParentId()) {
            EnterpriseRelationEntity supplierRelationEntity = new EnterpriseRelationEntity();
            supplierRelationEntity.setEnterpriseParentId(supplierAddDto.getSupplierParentId());
            supplierRelationEntity.setEnterpriseId(enterprise.getId());
            if (!enterpriseRelationService.save(supplierRelationEntity)) {
                throw new SysException("A00001", "保存失败！");
            }
        }

    }

    /**
     * 查询企业类别（企业类别）是核心企业和集团的企业信息，注意判断停用状态（stopStatus）和审核状态（approveStatus）。
     *
     * @param user 登录用户
     * @return 企业列表
     */
    @Override
    public List<EnterpriseEntity> getByLoginUser(User user) {
        /*TODO*/
        System.out.println("=============--------@@@@@@@@@@@@@@@@@@");
        System.out.println(user);
        LambdaQueryWrapper<EnterpriseEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EnterpriseEntity::getEnterpriseParentId,user.getEnterpriseId())
                .eq(EnterpriseEntity::getCategory,UserCategoryConstant.USER_CATEGORY_ENTERPRISE.getKey())
                .eq(EnterpriseEntity::getStopStatus,EnterpriseStopStatusEnum.ENTERPRISE_STATUS_USING.getCode())
                .eq(EnterpriseEntity::getApproveStatus,ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey());
        List<EnterpriseEntity> list = this.list(lambdaQueryWrapper);
        list.add(0,this.getById(user.getEnterpriseId()));
        return list;
    }

    /**
     * 获取所有供应商数据-黑/白名单下拉框
     *
     * @param user 登录用户
     * @return 企业列表
     */
    @Override
    public List<EnterpriseEntity> getAllSupplier(User user) throws SysException {
        /*TODO*/
        LambdaQueryWrapper<EnterpriseRelationEntity> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.eq(EnterpriseRelationEntity::getIsBlacklist,BlackListTypeEnum.BLACK_LIST_TYPE.getKey());
        List<EnterpriseRelationEntity> list1 = enterpriseRelationService.list(lambdaQueryWrapper1);
        List<String> ids = new LinkedList<>();
        for(EnterpriseRelationEntity enterpriseRelationEntity:list1){
            ids.add(enterpriseRelationEntity.getEnterpriseId());
        }
        LambdaQueryWrapper<EnterpriseEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .notIn(EnterpriseEntity::getId,ids)
                .eq(EnterpriseEntity::getStopStatus,EnterpriseStopStatusEnum.ENTERPRISE_STATUS_USING.getCode())
                .eq(EnterpriseEntity::getCategory,UserCategoryConstant.USER_CATEGORY_SUPPLIER.getKey());
        List<EnterpriseEntity> list = this.list(lambdaQueryWrapper);
        System.out.println("**************");
        System.out.println(list1);
        System.out.println(list);
        System.out.println("**************");
        return list;
    }

    /**
     * 企业信息唯一性验证
     *
     * @param info 企业名称或社会信用代码
     * @param type 参数类型 type=1,info表示企业全称，type=2，info表示统一社会信用代码
     */
    @Override
    public void checkEnterprise(String info, String type) throws SysException {
        LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (StringConstant.TYPE_ONE.equals(type)) {
            queryWrapper.eq(EnterpriseEntity::getEnterpriseName, info);
        } else if (StringConstant.TYPE_TWO.equals(type)) {
            queryWrapper.eq(EnterpriseEntity::getSocialCreditCode, info);
        } else {
            throw new SysException("参数类型不正确");
        }
        //根据企业名称或者信用代码查询企业信息
        List<EnterpriseEntity> list = this.list(queryWrapper);
        if (!CollectionUtils.isEmpty(list)) {
            if (ApproveStatusConstant.APPROVE_STATUS_ING.getKey().equals(list.get(0).getApproveStatus())) {
                throw new SysException("贵司相关信息正在审核中，请勿重复注册");
            } else if (ApproveStatusConstant.APPROVE_STATUS_AGREE.getKey().equals(list.get(0).getApproveStatus())) {
                //注册时，根据企业id查询经办人手机号和姓名 rpc接口待提供
                Result result = userCenterFeign.getUserByEnterpriseId(list.get(0).getId());
                if (ResultCode.SUCCESS.getCode() != result.getCode()) {
                    throw new SysException("贵公司没有注册经办人账号，请联系管理员");
                }
                UserEntity userEntity = JSON.parseObject(JSON.toJSONString(result.getResult().get("data")), UserEntity.class);
                //贵司已注册本平台，注册经办人为：
                //张三 13498929831
                throw new SysException("贵司已注册本平台，注册经办人为:" + userEntity.getUserName() + " " + userEntity.getUserPhone());
            }

        }
    }

    @Override
    public List<EnterpriseListDto> listByLoginUser(User user) throws SysException {
        List<EnterpriseEntity> enterprises;
        if (UserCategoryConstant.USER_CATEGORY_GROUP.getKey().equals(user.getUserCategory())) {
            LambdaQueryWrapper<EnterpriseEntity> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(EnterpriseEntity::getCategory, 0);
            enterprises = this.list(queryWrapper);
        } else {
            enterprises = Collections.singletonList(this.getById(user.getEnterpriseId()));
        }
        List<EnterpriseListDto> result = QmBeanUtils.copyListProperties(enterprises, EnterpriseListDto::new);
//        List<Integer> ids = result.stream().map(EnterpriseListDto::getId).collect(Collectors.toList());
//        QueryWrapper<LegalEntity> legalQueryWrapper = new QueryWrapper<>();
//        legalQueryWrapper.in(LegalEntity.COL_ENTERPRISE_ID, ids);
//        List<LegalEntity> legalEntities = legalService.list(legalQueryWrapper);
//        Map<Integer, LegalEntity> maps = legalEntities.stream().collect(Collectors.toMap(LegalEntity::getEnterpriseId, Function.identity(), (key1, key2) -> key2));
//        for (EnterpriseListDto enterpriseListDto : result) {
//            LegalEntity legalEntity = maps.get(enterpriseListDto.getId());
//            if (legalEntity != null) {
//                enterpriseListDto.setLegalIdentification(legalEntity.getLegalIdentification());
//                enterpriseListDto.setLegalUserName(legalEntity.getLegalUserName() + "/" + legalEntity.getLegalIdentification());
//                enterpriseListDto.setLegalPhone(legalEntity.getLegalPhone());
//                enterpriseListDto.setLegalCertificateExpireTime(legalEntity.getLegalCertificateExpireTime());
//                enterpriseListDto.setLegalIdentificationLongTime(legalEntity.getLegalIdentificationLongTime());
//                enterpriseListDto.setFrontIdentityCard(legalEntity.getFrontIdentityCard());
//                enterpriseListDto.setBackIdentityCard(legalEntity.getBackIdentityCard());
//                enterpriseListDto.setAuthorizationLetter(legalEntity.getAuthorizationLetter());
//                enterpriseListDto.setFileList(this.createFileIdNameList(enterpriseListDto.getAuthorizationLetter(), "AUTHORIZATION_LETTER"));
//            }
//        }
        return result;
    }

    /**
     * 创建文件id名称对象集合
     *
     * @param fileIds 融资票据对象
     * @return 文件id名称对象集合
     */
    private List<FileIdNameDto> createFileIdNameList(String fileIds, String type) throws SysException {
        if (StringUtils.isBlank(fileIds)) {
            return new ArrayList<>(0);
        }
        String[] fileIdArr = fileIds.split(",");
        if (fileIdArr.length <= 0) {
            return new ArrayList<>(0);
        }
        FileInfoPar fileInfoPar = new FileInfoPar();
        fileInfoPar.setBucket(type);
        fileInfoPar.setIds(Arrays.asList(fileIdArr));
        Result fileFeignResult = fileCenterFeign.getFileNameByIds(fileInfoPar);
        String msg = "调用文件中心失败！";
        if (SUCCESS.getCode() != fileFeignResult.getCode()) {
            throw new SysException(msg);
        }
        Object fileListObj = fileFeignResult.getResult().get("list");
        if (null == fileListObj) {
            throw new SysException(msg);
        }
        List<FileInfo> fileInfoList = JSON.parseArray(JSON.toJSONString(fileListObj), FileInfo.class);
        if (fileIdArr.length != fileInfoList.size()) {
            throw new SysException(msg);
        }
        Map<String, List<FileInfo>> fileInfoMap = fileInfoList.stream().collect(Collectors.groupingBy(FileInfo::getObjectId));
        List<FileIdNameDto> result = new ArrayList<>();
        for (String fileId : fileIdArr) {
            FileIdNameDto fileIdNameDto = new FileIdNameDto();
            fileIdNameDto.setId(fileId);
            List<FileInfo> oneFileList = fileInfoMap.get(fileId);
            if (CollectionUtils.isEmpty(oneFileList)) {
                throw new SysException("调用文件中心失败！");
            }
            fileIdNameDto.setName(oneFileList.get(0).getFileName());
            result.add(fileIdNameDto);
        }
        return result;
    }

}